﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ch01
{
    public partial class TerrDeidView : Form
    {
        public TerrDeidView()
        {
            InitializeComponent();
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
           
            //获取当前选中的节点
            TreeNode tn = this.treeView1.SelectedNode;

            //获取父节点
            TreeNode ptn = tn.Parent;
          
            string sql = "select s.*,g.gradename from student s,grade g where s.gradeid=g.no and 1=1";
            if (tn.Level==1)
            {
                sql += " and s.gradeid="+tn.Tag;
            }
            else if (tn.Level == 2)
            {
                sql += string.Format(" and s.gradeid={0} and sex='{1}'", ptn.Tag, tn.Text);
            }
            dataGridView1.DataSource = DBHelper.SelectTable(sql);
        }
    }
}
